"use strict";

/**
 * @fileoverview audio 插件
 */
var context = require('./context');

var index = 0;

function audio(vm) {
  this.vm = vm;
}

audio.prototype.onUpdate = function () {
  this.audios = [];
};

audio.prototype.onParse = function (node) {
  if (node.name == 'audio') {
    if (!node.attrs.id) node.attrs.id = 'a' + index++;
    this.audios.push(node.attrs.id);
  }
};

audio.prototype.onLoad = function () {
  var _this = this;

  setTimeout(function () {
    for (var i = 0; i < _this.audios.length; i++) {
      var ctx = context.get(_this.audios[i]);
      ctx.id = _this.audios[i];

      _this.vm._videos.push(ctx);
    }
  }, 50);
};

module.exports = audio;